package ast;

import mem.interfaces.IMem;
import environnement.interfaces.IEnv;
import ast.interfaces.IAST;
import ast.interfaces.IASTwhile;

public class ASTwhile implements IASTwhile {

	private IAST condiction;
	private IAST prog;
	
	public ASTwhile(IAST condiction, IAST prog) {
		super();
		this.condiction = condiction;
		this.prog = prog;
	}

	@Override
	public Object eval(IAST ast, IEnv e, IMem m) {

		while((Boolean) getCondiction().eval(ast, e, m)){
			prog.eval(ast, e, m);
		}
		return null;
	}

	public IAST getCondiction() {
		return condiction;
	}

	public void setCondiction(IAST condiction) {
		this.condiction = condiction;
	}

	public IAST getProg() {
		return prog;
	}

	public void setProg(IAST prog) {
		this.prog = prog;
	}

	@Override
	public String toTreeString(String ident,IEnv e,IMem m) {
		return ident + "WHILE " + getCondiction().toTreeString(ident, e, m) +" "+ getProg().toTreeString(ident, e, m);
	}

	
}
